﻿package Chapter05;
// 將 StepIntoJava.java 內容替換為下列代碼即可運行
//======================================================================
//public class StepIntoJava {
//	public static void main(String[] args) {
//		SimpleDotComGame app = new SimpleDotComGame();
//		app.run();
//	}	
//}
//======================================================================

public class SimpleDotComGame {
	void run() {
		//宣告一個 DotCom 物件
		SimpleDotCom dotCom = new SimpleDotCom();
		
		//隨機取得空白 cell,
		//設定到 DotCom 物件裡
		int startLoc = (int)(Math.random() * 5);
		int[] locs = {startLoc, startLoc+1, startLoc+2};
		dotCom.setLocationCells(locs);
		
		//取得使用者輸入
		GameHelper helper = new GameHelper();
		String guess;
		guess = helper.getUserInput("請輸入要攻擊的位置: ");
		int guessCount = 1;
		while(true) {
			String result = dotCom.checkYourself(guess);
			if (result.equals("hit")) {
				//呼叫物件的 RemoveCell
				dotCom.removeCell(guess);
				System.out.println("你擊中了!!");
			} else if (result.equals("kill")) {
				break;
			}

			guess = helper.getUserInput("請輸入要攻擊的位置: ");
			guessCount++;
		}
		
		System.out.println("恭喜你贏得勝利, 一共猜了 "+guessCount+" 次");
	}	
}
